//
//  MainGoodsCell.m
//  WeiYiMei
//
//  Created by 李叶夫 on 2019/4/11.
//  Copyright © 2019年 liyefu. All rights reserved.
//

#import "MainGoodsCell.h"
//#import "ANGradientButton.h"

@interface MainGoodsCell ()

@property (nonatomic, strong) UIImageView *icon;
@property (nonatomic, strong) UILabel *goodsTitleLab;
@property (nonatomic, strong) UILabel *goodsDesLab;
@property (nonatomic, strong) UILabel *goodsVipPriceLab;
@property (nonatomic, strong) UILabel *goodsVipPrice;
@property (nonatomic, strong) UILabel *goodsPriceLab;
//@property (nonatomic, strong) ANGradientButton *shoppingCart;

@property (nonatomic, strong) UILabel *shopNameLab;
@property (nonatomic, strong) UIView *shopNameView;

@end

@implementation MainGoodsCell

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        [self setupSubViews];
    }
    return self;
}

- (void)setEntity:(GoodsEntity *)entity
{
    _entity = entity;
    self.goodsTitleLab.text = entity.goodsName;
    self.goodsDesLab.text = entity.summary;
    self.goodsVipPrice.text = [NSString stringWithFormat:@"￥%@",[NSString decimalNumberWithDouble:entity.memberPrice.doubleValue]];
    NSString *price = [NSString stringWithFormat:@"原价:￥%@",[NSString decimalNumberWithDouble:entity.price.doubleValue]];
    NSMutableAttributedString *attri = [[NSMutableAttributedString alloc] initWithString:price];
    [attri setAttributes:@{NSForegroundColorAttributeName:kColor888888,NSFontAttributeName:[UIFont systemFontOfSize:12]} range:NSMakeRange(0, 3)];
    [attri setAttributes:@{NSFontAttributeName:[UIFont boldSystemFontOfSize:12],NSForegroundColorAttributeName:kColor333333} range:NSMakeRange(3, price.length-3)];
    self.goodsPriceLab.attributedText = attri;
    NSString *url = [NSString stringWithFormat:@"%@%@",SERVERADDRS,entity.filePath];
    [self.icon sd_setImageWithURL:[NSURL URLWithString:url] placeholderImage:[UIImage imageNamed:@"pic_moren"]];
    
    self.shopNameLab.text = entity.consumerName;

    
}

- (void)setShowShopName:(BOOL)showShopName
{
    _showShopName = showShopName;
    self.shopNameView.hidden = !showShopName;
}

- (void)setupSubViews
{
    self.icon = [[UIImageView alloc] init];
    self.icon.image = [UIImage imageNamed:@"pic_moren"];
    self.icon.layer.masksToBounds = YES;
    self.icon.layer.cornerRadius = 4;
    [self addSubview:self.icon];
    
    self.shopNameView = [[UIView alloc] init];
    self.shopNameView.backgroundColor = UIColorFromRGB(0x090909);
    self.shopNameView.alpha = 0.4;
    [self.icon addSubview:self.shopNameView];
    
    self.shopNameLab = [[UILabel alloc] init];
    self.shopNameLab.font = [UIFont systemFontOfSize:12];
    self.shopNameLab.textColor = [UIColor whiteColor];
    self.shopNameLab.textAlignment = NSTextAlignmentCenter;
    [self.shopNameView addSubview:self.shopNameLab];
    
    self.goodsTitleLab = [[UILabel alloc] init];
    self.goodsTitleLab.textColor = kColor333333;
    self.goodsTitleLab.font = [UIFont boldSystemFontOfSize:14];
    [self addSubview:self.goodsTitleLab];
    
    self.goodsDesLab = [[UILabel alloc] init];
    self.goodsDesLab.textColor = kColor666666;
    self.goodsDesLab.font = [UIFont systemFontOfSize:12];
    [self addSubview:self.goodsDesLab];
    
    
#warning 会员价显示控制
//    if (UserUtils.shared.showVip) {
    
        self.goodsVipPriceLab = [[UILabel alloc] init];
        self.goodsVipPriceLab.textColor = kColor888888;
        self.goodsVipPriceLab.font = [UIFont systemFontOfSize:12];
        self.goodsVipPriceLab.text = @"会员价:";
        [self addSubview:self.goodsVipPriceLab];
        
        self.goodsVipPrice = [[UILabel alloc] init];
        self.goodsVipPrice.textColor = kColorFF2C2C;
        self.goodsVipPrice.font = [UIFont boldSystemFontOfSize:12];
        [self addSubview:self.goodsVipPrice];
//    }
    
    
    self.goodsPriceLab = [[UILabel alloc] init];
    [self addSubview:self.goodsPriceLab];
    
//    self.shoppingCart = [[ANGradientButton alloc] initWithFrame:CGRectMake(0, 0, 73, 24)];
//    [self.shoppingCart setTitle:@"加入购物车" forState:UIControlStateNormal];
//    self.shoppingCart.titleLabel.font = [UIFont systemFontOfSize:12];
//    self.shoppingCart.layer.cornerRadius = 12;
//    self.shoppingCart.layer.masksToBounds = YES;
//    
//    
//    [self addSubview:self.shoppingCart];
    
    
    [self.icon mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self).offset(kWidth(10));
        make.left.equalTo(self).offset(kWidth(16));
        make.width.equalTo(@(kWidth(115)));
        make.height.equalTo(@(75/115.0*kWidth(115)));
    }];
    
    [self.shopNameView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.bottom.right.equalTo(self.icon);
        make.height.equalTo(@18);
    }];
    
    [self.shopNameLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.equalTo(self.shopNameView);
    }];
    
    [self.goodsTitleLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.icon);
        make.right.lessThanOrEqualTo(self).offset(-kWidth(16));
        make.left.equalTo(self.icon.mas_right).offset(kWidth(10));
    }];
    
    [self.goodsDesLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.goodsTitleLab);
        make.top.equalTo(self.goodsTitleLab.mas_bottom).offset(kWidth(10));
        make.right.lessThanOrEqualTo(self).offset(-kWidth(16));
    }];
    
    [self.goodsVipPriceLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(self.goodsVipPrice.mas_left);
        make.bottom.equalTo(self.icon);
    }];
    
    [self.goodsVipPrice mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(self).offset(kWidth(-16));
        make.centerY.equalTo(self.goodsVipPriceLab);
    }];
    
    [self.goodsPriceLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.goodsTitleLab);
        make.bottom.equalTo(self.icon);
    }];
    
//    [self.shoppingCart mas_makeConstraints:^(MASConstraintMaker *make) {
//        make.right.equalTo(self).offset(-kWidth(16));
//        make.centerY.equalTo(self.goodsVipPrice);
//        make.width.equalTo(@73);
//        make.height.equalTo(@24);
//    }];
}

@end
